<?
class TemplateNews{
    var $fieldsort = '';//Sắp xếp theo trường nào
    var $sort		= '';//Sắp xếp tăng hay giảm
    var $page		= 1;//Trang hiện tại
    var $page_size = 5;//Kích cỡ 1 trang hiển thị bao nhiêu kết quả
    public function news() {
        $slides = db_array('SELECT *
                        FROM news
                        WHERE new_active = 1
                        ORDER BY new_date DESC
                        LIMIT '.($this->page - 1)*$this->page_size.' ,'.$this->page_size);
        return $slides;
    }  
    public function news_total() {
        $arr = db_array('SELECT new_id
                        FROM news
                        WHERE new_active = 1
                        ');
        return count($arr);
    }    
    public function news_detail($new_id) {
        $arr = db_first('SELECT *
                        FROM news
                        WHERE new_id ='.$new_id);
        return $arr;
    }     
    public function news_older($new_id) {
        $cur_news_date = db_first('SELECT new_date FROM news WHERE new_id ='.$new_id);
        $arr = db_array('SELECT *
                        FROM news
                        WHERE new_active = 1
                        AND new_date < '.$cur_news_date['new_date'].'
                        ORDER BY new_date DESC
                        LIMIT 5');
        return $arr;
    }  
    public function news_cat_id_inf($new_cat_id) {
        $arr = db_first('SELECT *
                        FROM categories_multi
                        WHERE cat_type = "news"
                        AND cat_id = '.$new_cat_id);
        return $arr;
    }
    public function news_follow_cat_id($new_cat_id) {
        $arr = db_array('SELECT *
                        FROM news
                        WHERE new_active = 1
                        AND new_cat_id = '.$new_cat_id.'
                        ORDER BY new_date DESC
                        LIMIT '.($this->page - 1)*$this->page_size.' ,'.$this->page_size);
        return $arr;
    }
    public function news_follow_cat_id_total($new_cat_id) {
        $arr = db_array('SELECT new_id
                        FROM news
                        WHERE new_active = 1
                        AND new_cat_id ='.$new_cat_id);
        return count($arr);
    }    
}
?>